package com.summer.springbootorderrabbitmqproducer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class TTLRabbitConfiguration {
    //声明fanout交换机
    @Bean
    public DirectExchange directTTLExchange(){
        return new DirectExchange("ttl_direct_order_exchange",true,false);
    }
    //队列的过期时间
    //声明队列
    @Bean
    public Queue ttldirectsmsQueue(){
       Map<String, Object> args = new HashMap<>();
       args.put("x-message-ttl",5000);
       args.put("x-dead-letter-exchange","dead_direct_exchange");
       args.put("x-dead-letter-routing-key","dead");
        return new Queue("ttl.direct.queue",true,false,false,args);
    }
    @Bean
    public Queue ttldirectMessagesmsQueue(){
        return new Queue("ttl.message.direct.queue",true,false,false);
    }

    @Bean
    public Binding directemailBinding(){
        return BindingBuilder.bind(ttldirectsmsQueue()).to(directTTLExchange()).with("ttl");
    }
    @Bean
    public Binding directMessageBinding(){
        return BindingBuilder.bind(ttldirectMessagesmsQueue()).to(directTTLExchange()).with("ttlmessage");
    }
}
